<?php
declare (strict_types = 1);

namespace app\api\controller;

use bbweb\basic\BaseController;
use think\Request;

//require_once __DIR__ .'/AipSpeech.php';

class BaiduYun extends BaseController
{
    /**
     * 广告接口
     * @param  \think\Request  $req
     * @return \think\Response
     */
    public function mp3(Request $req)
    {
        //echo __DIR__ .'/AipSpeech.php';die;
        $app_id = '23562529';
        $app_key = 'nCY785mQa1ldiF6ke6pfVqHL';
        $secret_key = 'GlEimQiHdEqEgZKEZX0MsGSQH3X1qQjq';

        $client = new AipSpeech($app_id, $app_key, $secret_key);

        $result = $client->synthesis('位于邢台市隆尧县随便小区二号楼二单元202的小门神正在报警、请尽快确认', 'zh', 1, array(
            'vol' => 5,
        ));

        // 识别正确返回语音二进制 错误则返回json 参照下面错误码
        if(!is_array($result)){
            file_put_contents('audio.mp3', $result);
        }
    }
}
